using System.Windows.Forms;
using WindowsLive.Writer.Api;

namespace SignaturePlugin
{
    [WriterPlugin("98e641d7-7380-472d-9d51-93210cea5882", "Signature Plugin",
        PublisherUrl = "http://scottisafooldev.spaces.live.com",
        Description = "This plugin will automatically put a signature in based on what has been configured in the options for the blog you're writing for.",
        ImagePath = "writer.png",
        HasEditableOptions = true)]

    public class Plugin : HeaderFooterSource
    {
        Settings m_default;

        public override void Initialize(IProperties pluginOptions)
        {
            base.Initialize(pluginOptions);
            m_default = new Settings(pluginOptions);
        }

        public override string GeneratePreviewHtml(ISmartContent smartContent, IPublishingContext publishingContext, out HeaderFooterSource.Position position)
        {
            position = Position.Footer;            
            string blogname = publishingContext.BlogName;
            string signature = GetSignature(blogname);
            return signature;
        }

        public override string GeneratePublishHtml(IWin32Window dialogOwner, ISmartContent smartContent, IPublishingContext publishingContext, bool publish, out HeaderFooterSource.Position position)
        {
            position = Position.Footer;
            string blogname = publishingContext.BlogName;
            string signature = GetSignature(blogname);
            return signature;
        }

        public override void EditOptions(IWin32Window dialogOwner)
        {
            frmOptions op = new frmOptions(m_default);
            op.ShowDialog();
        }

        private string GetSignature(string blogname)
        {
            string settingname = string.Format("({0}).SignatureText", blogname);
            m_default.settingname = settingname;
            string sig = m_default.Signature;
            return sig;
        }
    }
}
